home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / pvm34b3.zip / pvm34b3 / pvm3 / examples / taskf.c < prev    next >
C/C++ Source or Header  |  1997-07-22  |  6KB  |  195 lines

  1.  
  2. static char rcsid[] =
  3.     "$Id: taskf.c,v 1.3 1997/07/09 13:26:17 pvmsrc Exp $";
  4.  
  5. /*
  6.  *         PVM version 3.4:  Parallel Virtual Machine System
  7.  *               University of Tennessee, Knoxville TN.
  8.  *           Oak Ridge National Laboratory, Oak Ridge TN.
  9.  *                   Emory University, Atlanta GA.
  10.  *      Authors:  J. J. Dongarra, G. E. Fagg, M. Fischer
  11.  *          G. A. Geist, J. A. Kohl, R. J. Manchek, P. Mucci,
  12.  *         P. M. Papadopoulos, S. L. Scott, and V. S. Sunderam
  13.  *                   (C) 1997 All Rights Reserved
  14.  *
  15.  *                              NOTICE
  16.  *
  17.  * Permission to use, copy, modify, and distribute this software and
  18.  * its documentation for any purpose and without fee is hereby granted
  19.  * provided that the above copyright notice appear in all copies and
  20.  * that both the copyright notice and this permission notice appear in
  21.  * supporting documentation.
  22.  *
  23.  * Neither the Institutions (Emory University, Oak Ridge National
  24.  * Laboratory, and University of Tennessee) nor the Authors make any
  25.  * representations about the suitability of this software for any
  26.  * purpose.  This software is provided ``as is'' without express or
  27.  * implied warranty.
  28.  *
  29.  * PVM version 3 was funded in part by the U.S. Department of Energy,
  30.  * the National Science Foundation and the State of Tennessee.
  31.  */
  32.  
  33. /**********************************************************************
  34.  *    Filename:     taskf.c
  35.  *
  36.  *  contains functions used in mailbox example codes
  37.  *
  38.  *  task0.c task1.c task_end.c
  39.  *  lmbi.c gmbi.c rme.c
  40.  *  others ???
  41.  *
  42.  *********************************************************************/
  43.  
  44. #include "stdio.h"
  45. #include "pvm3.h"
  46.  
  47. /**********************************************************************
  48.  *  Function: display_incomming_parameters
  49.  *
  50.  *  displays the command line parameters from program
  51.  *********************************************************************/
  52. void
  53. display_incomming_parameters( who, argc, argv )
  54. char *who;
  55. int argc;
  56. int *argv;
  57. {
  58.     char *me = "display_incomming_parameters";
  59.     int i;
  60.     printf( "\n%s: %d incoming parameters to main.\n", who, argc );
  61.     for ( i=0 ; i < argc ; i++ )
  62.         printf( "%s: argv[%d] = <%s>\n", who, i, argv[i] );
  63. } /* display_incomming_parameters */
  64.  
  65.  
  66.  
  67. /**********************************************************************
  68.  *  Function: get_flagstring
  69.  *
  70.  *  flags: Incoming integer that represents the sum of Mbox flags.
  71.  *
  72.  *  returns: Outgoing string of flags set.
  73.  *        may have:    PvmMboxDefault        d =  0
  74.  *                PvmMboxPersistent    p =  1
  75.  *                PvmMboxMultiInstance    m =  2
  76.  *                PvmMboxOverWritable    o =  4
  77.  *                PvmMboxFirstAvail    f =  8
  78.  *                PvmMboxReadAndDelete    r = 16
  79.  *
  80.  *  returns a pointer to a string containing flags set
  81.  *  returns NULL pointer on error
  82.  *********************************************************************/
  83. char *
  84. get_flagstring( flags )
  85. int flags;
  86. {
  87.     char *me = "get_flagstring";
  88.     int size = 0;
  89.     char *flagstring = ( char * ) NULL;
  90.  
  91.     /*
  92.      *  string space to return
  93.      */
  94.     if ( (flagstring = (char *) calloc( 255, sizeof(char) )) == NULL ) {
  95.         printf( "\n%s: failed on calloc.\n", me );
  96.         return( ( char * ) NULL );
  97.     }
  98.  
  99.     /* set to null so that empty string test works */
  100.     flagstring[0] = '\0';
  101.  
  102.     if ( flags == PvmMboxDefault ) {
  103.         strcat( flagstring, "PvmMboxDefault " );
  104.     }
  105.     else {
  106.         if ( flags >= PvmMboxReadAndDelete ) {
  107.             strcat( flagstring, "PvmMboxReadAndDelete " );
  108.             flags -= PvmMboxReadAndDelete;
  109.         }
  110.         if ( flags >= PvmMboxFirstAvail ) {
  111.             strcat( flagstring, "PvmMboxFirstAvail " );
  112.             flags -= PvmMboxFirstAvail;
  113.         }
  114.         if ( flags >= PvmMboxOverWritable ) {
  115.             strcat( flagstring, "PvmMboxOverWritable " );
  116.             flags -= PvmMboxOverWritable;
  117.         }
  118.         if ( flags >= PvmMboxMultiInstance ) {
  119.             strcat( flagstring, "PvmMboxMultiInstance " );
  120.             flags -= PvmMboxMultiInstance;
  121.         }
  122.         if ( flags >= PvmMboxPersistent ) {
  123.             strcat( flagstring, "PvmMboxPersistent " );
  124.             flags -= PvmMboxPersistent;
  125.         }
  126.     }
  127.     return( flagstring );
  128. } /* get_flagstring */
  129.  
  130.  
  131.  
  132. /**********************************************************************
  133.  *  Function: set_flags
  134.  *
  135.  *  flagsin: Incoming string containing characters representing the
  136.  *   Mbox switches set.
  137.  *           An empty string is assumed to be "d" for PvmMboxDefault.
  138.  *        valid chars are ( d p m o f r ) in any order.
  139.  *        Any bogus characters are ignored...
  140.  *
  141.  *  flagstring: Outgoing string of flags set.
  142.  *        may have:    PvmMboxDefault        d =  0
  143.  *                PvmMboxPersistent    p =  1
  144.  *                PvmMboxMultiInstance    m =  2
  145.  *                PvmMboxOverWritable    o =  4
  146.  *                PvmMboxFirstAvail    f =  8
  147.  *                PvmMboxReadAndDelete    r = 16
  148.  *
  149.  *  returns a positive integer representing addition of all set flags.
  150.  *  returns a negative integer to indicate an error condition
  151.  *********************************************************************/
  152. int
  153. set_flags( flagsin, flagstring )
  154. char *flagsin;
  155. char **flagstring;
  156. {
  157.     char *me = "set_flags";
  158.     int size = 0;
  159.     int flags = PvmMboxDefault;
  160.  
  161.     /*
  162.      *  check for existance of flag character and
  163.      *  set results accordingly
  164.      */
  165.  
  166.     /* ambiguious but do anyway... */
  167.     if ( strchr( flagsin, 'd' ) != NULL ) {
  168.         flags |= PvmMboxDefault;
  169.     }
  170.     if ( strchr( flagsin, 'r' ) != NULL ) {
  171.         flags |= PvmMboxReadAndDelete;
  172.     }
  173.     if ( strchr( flagsin, 'f' ) != NULL ) {
  174.         flags |= PvmMboxFirstAvail;
  175.     }
  176.     if ( strchr( flagsin, 'o' ) != NULL ) {
  177.         flags |= PvmMboxOverWritable;
  178.     }
  179.     if ( strchr( flagsin, 'm' ) != NULL ) {
  180.         flags |= PvmMboxMultiInstance;
  181.     }
  182.     if ( strchr( flagsin, 'p' ) != NULL ) {
  183.         flags |= PvmMboxPersistent;
  184.     }
  185.  
  186.     /*
  187.      *  get flags.
  188.      *  flags other than those expected "drfomp" will return as
  189.      *  PvmMboxDefault
  190.      */
  191.     if ( (*flagstring = get_flagstring( flags )) == NULL ) return( -1 );
  192.     return( flags );
  193. } /* set_flags */
  194.  
  195.